import optionsx from '@/Echarts/饼图1'
import * as echarts from 'echarts'
let options = JSON.parse(JSON.stringify(optionsx))
// const { echarts } = window

export default (element, data) => {
  const old = echarts.getInstanceByDom(element)
  if (old) old.dispose()
  const chart = echarts.init(element, 'theme')
  // eslint-disable-next-line no-unused-vars
  // const source = data.map((res) => {
  //   return {
  //     name: res.type,
  //     value: res.Number
  //   }
  // })
  options.legend.data = data.legendData || ['链接访问', '邮件推送', '图片广告', '视频广告', '搜索引擎'];
  options.series[0].name = data.name || '半径模式';
  options.series[0].data = data.seriesData || [
    { value: 350, name: '链接访问' },
    { value: 350, name: '邮件推送' },
    { value: 250, name: '图片广告' },
    { value: 150, name: '视频广告' },
    { value: 650, name: '搜索引擎' }
  ];
  chart.setOption(options)
  return chart
}
